package com.woniuxy.test04;

import org.junit.Test;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author author
 * @Create 2023-09-15 9:46
 */
public class MyTest {

    @Test
    public void test01() throws IOException {
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("my.bin"));
        Student s1=new Student(1,"zs",11,"x","");
        Student s2=new Student(2,"ls",11,"xy","");
        Student s3=new Student(3,"ww",11,"xyz","");
        List<Student> students=new ArrayList<>();
        students.add(s1);
        students.add(s2);
        students.add(s3);
        //使用序列化，将对象写入二进制文件
        oos.writeObject(students);
    }
    @Test
    public void test02() throws IOException, ClassNotFoundException {
        ObjectInputStream oos=new ObjectInputStream(new FileInputStream("my.bin"));
        List<Student> students = (List<Student>) oos.readObject();
        students.forEach(System.out::println);
    }

    @Test
    public void test03() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("my.bin"));
        Aaa aaa=new Aaa(1,"xxx",new Teacher(1,"xxx"));
        oos.writeObject(aaa);
    }
}


